﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;

namespace AvantGameMachine.Graphics
{
    class DeviceInfo
    {
        private int lights = 0;
        private int clipping_planes = 0;
        private int model_stack = 0;
        private int projection_stack = 0;
        private int texture_stack = 0;
        private int bpp = 0;
        private int max_tex3d = 0;
        private int max_tex2d = 0;
        private int name_stack = 0;
        private int list_stack = 0;
        private int max_poly = 0;
        private int attrib_stack = 0;
        private int buffers = 0;

        private int stencil;
        private int accum;
        private int rgba;
        private int index;
        private int double_buffer;
        private int stereo;

        private int convolution_width = 0;
        private int convolution_height = 0;
        private int max_index = 0;
        private int max_vertex = 0;
        private int texture_units = 0;

        internal DeviceInfo()
        {
            Gl.glGetIntegerv(Gl.GL_MAX_LIGHTS, out lights);
            Gl.glGetIntegerv(Gl.GL_MAX_CLIP_PLANES, out clipping_planes);
            Gl.glGetIntegerv(Gl.GL_MAX_MODELVIEW_STACK_DEPTH, out model_stack);
            Gl.glGetIntegerv(Gl.GL_MAX_PROJECTION_STACK_DEPTH, out projection_stack);
            Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_STACK_DEPTH, out texture_stack);
            Gl.glGetIntegerv(Gl.GL_SUBPIXEL_BITS, out bpp);
            Gl.glGetIntegerv(Gl.GL_MAX_3D_TEXTURE_SIZE, out max_tex3d);
            Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_SIZE, out max_tex2d);
            Gl.glGetIntegerv(Gl.GL_MAX_NAME_STACK_DEPTH, out name_stack);
            Gl.glGetIntegerv(Gl.GL_MAX_LIST_NESTING, out list_stack);
            Gl.glGetIntegerv(Gl.GL_MAX_EVAL_ORDER, out max_poly);
            Gl.glGetIntegerv(Gl.GL_MAX_ATTRIB_STACK_DEPTH, out attrib_stack);
            Gl.glGetIntegerv(Gl.GL_AUX_BUFFERS, out buffers);
            Gl.glGetBooleanv(Gl.GL_STENCIL, out stencil);
            Gl.glGetBooleanv(Gl.GL_ACCUM, out accum);
            Gl.glGetBooleanv(Gl.GL_RGBA_MODE, out rgba);
            Gl.glGetBooleanv(Gl.GL_INDEX_MODE, out index);
            Gl.glGetBooleanv(Gl.GL_DOUBLEBUFFER, out double_buffer);
            Gl.glGetBooleanv(Gl.GL_STEREO, out stereo);
        }

        internal void ShowDeviceInfo()
        {
            AGMPlatform.log.Debug ("OpenGL driver informations:");
            AGMPlatform.log.Debug(string.Format("==========================="));
            AGMPlatform.log.Debug(string.Format("OpenGL version: {0}", Gl.glGetString(Gl.GL_VERSION)));
            AGMPlatform.log.Debug(string.Format("Software implementation: {0}", Gl.glGetString(Gl.GL_VENDOR)));
            AGMPlatform.log.Debug(string.Format("Renderer: {0}", Gl.glGetString(Gl.GL_RENDERER)));
            AGMPlatform.log.Debug(string.Format("Supported extensions: {0}", Gl.glGetString(Gl.GL_EXTENSIONS)));

            AGMPlatform.log.Debug(string.Format("Double buffering: {0}", (double_buffer != 0 ? "yes" : "no")));
            AGMPlatform.log.Debug(string.Format("Stereo: {0}", (stereo != 0 ? "yes" : "no")));
            AGMPlatform.log.Debug(string.Format("Auxiliary buffer(s): {0}", buffers));
            AGMPlatform.log.Debug(string.Format("Stencil buffer: {0}", (stencil != 0 ? "yes" : "no")));
            AGMPlatform.log.Debug(string.Format("Accumulation buffer: {0}", (accum != 0 ? "yes" : "no")));

            AGMPlatform.log.Debug(string.Format("Bits per pixel: {0}", bpp));
            AGMPlatform.log.Debug(string.Format("RGBA color: {0}", (rgba != 0 ? "yes" : "no")));
            AGMPlatform.log.Debug(string.Format("Index color palette: {0}", (index != 0 ? "yes" : "no")));

            AGMPlatform.log.Debug(string.Format("Model stack size: {0}", model_stack));
            AGMPlatform.log.Debug(string.Format("Projection stack size: {0}", projection_stack));
            AGMPlatform.log.Debug(string.Format("Texture stack size: {0}", texture_stack));
            AGMPlatform.log.Debug(string.Format("Name stack size: {0}", name_stack));
            AGMPlatform.log.Debug(string.Format("List stack size: {0}", list_stack));
            AGMPlatform.log.Debug(string.Format("Attributes stack size: {0}", attrib_stack));

            AGMPlatform.log.Debug(string.Format("Maximum 3D texture size: {0}", max_tex3d));
            AGMPlatform.log.Debug(string.Format("Maximum 2D texture size: {0}", max_tex2d));
            AGMPlatform.log.Debug(string.Format("Maximum texture units: {0}", texture_units));

            AGMPlatform.log.Debug(string.Format("Maximum lights: {0}", lights));
            AGMPlatform.log.Debug(string.Format("Maximum clipping planes: {0}", clipping_planes));
            AGMPlatform.log.Debug(string.Format("Maximum evaluators equation order: {0}", max_poly));
            AGMPlatform.log.Debug(string.Format("Maximum convolution: {0}", convolution_width, convolution_height));
            AGMPlatform.log.Debug(string.Format("Maximum recommended index elements: {0}", max_index));
            AGMPlatform.log.Debug(string.Format("Maximum recommended vertex elements: {0}", max_vertex));
        }
    }
}
